package com.cskt.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2  //开启swagger2
public class SwaggerConfig {
    @Bean
    public Docket authApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("authApi")
                .apiInfo(authApiInfo())
                .select()
                //指定Swagger管理规则，将所有请求前缀为 /api纳入管理
//                .paths(Predicates.and(PathSelectors.regex("/api/*")))
                //排除请求路径前缀为 /error的控制器，主要是springboot自带的异常处理接口
//                .paths(Predicates.not(PathSelectors.regex("/error/*")))
                .apis(RequestHandlerSelectors.basePackage("com.cskt.controller"))
                .build();
    }
    private ApiInfo authApiInfo(){
        return new ApiInfoBuilder()
                .title("爱旅行-用户认证模块API")
                .description("提供用户认证相关接口")
                .version("v1.0")
                .build();
    }
}
